package com.tbit.uqbike.service.base.impl;

import com.tbit.uqbike.enums.SystemCodeEnum;
import com.tbit.uqbike.manager.exception.BaseException;
import com.tbit.uqbike.object.pojo.Countrys;
import com.tbit.uqbike.service.base.CountryService;
import com.tbit.uqbike.webmanager.dao.core.CountrysDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author MyWin E-mail:335918956@qq.com
 * @version 1.0
 * @createTime 2019-12-09 16:41
 */
@Service
public class CountryServiceImpl implements CountryService {
    @Autowired
    private CountrysDao countrysDao;

    @Override
    public boolean checkPhone(String country, String phone) {
        Countrys countrys = countrysDao.getCountrysByCode(country);
        if (null == countrys) {
            throw new BaseException(SystemCodeEnum.NOT_SUPPORT_SMS_CODE);
        }
        if (!StringUtils.isEmpty(countrys.getCountryPhoneRegex())) {
            if (phone.matches(countrys.getCountryPhoneRegex())) {
                return true;
            } else {
                throw new BaseException(SystemCodeEnum.PHONE_NOT_VALID);
            }
        } else {
            return true;
        }
    }
}
